<pre><span class="comment">/*
 * Fichier: Source1.java
 * Crée le: 28 novembre 2008.
 * Modifié: 7 juillet 2007.
 * Auteurs: Sébastien ESTIENNE.
 * SiteWeb: http://www.prog-info.org/
 * Email  : nom.prenom@domaine.com
 */</span>

<span class="keyword">package</span> highlighter;

<span class="keyword">import</span> java.util.ArrayList;
<span class="keyword">import</span> java.util.List;


<span class="comment2">/**
 * &lt;p&gt;Classe Source1 pour tester le JavaHighlighter.&lt;/p&gt;
 * <b>@author</b> Sébastien ESTIENNE.
 */</span>
<span class="keyword">public</span> <span class="keyword">class</span> Source1 <span class="keyword">extends</span> Object
{
   <span class="comment2">/** Attribut de type booléen. */</span>
   <span class="keyword">private</span> <span class="keyword">boolean</span> mb;
   
   <span class="comment2">/** Attribut de type entier. */</span>
   <span class="keyword">private</span> <span class="keyword">int</span> mi;
   
   <span class="comment2">/** Attribut de type long. */</span>
   <span class="keyword">private</span> <span class="keyword">long</span> ml;
   
   <span class="comment2">/** Attribut de type float. */</span>
   <span class="keyword">private</span> <span class="keyword">float</span> mf;
   
   <span class="comment2">/** Attribut de type double. */</span>
   <span class="keyword">private</span> <span class="keyword">double</span> md;
   
   <span class="comment2">/** Attribut de type byte. */</span>
   <span class="keyword">private</span> <span class="keyword">transient</span> <span class="keyword">byte</span> my;
   
   <span class="comment2">/** Attribut de type short. */</span>
   <span class="keyword">private</span> <span class="keyword">short</span> ms;
   
   <span class="comment2">/** Attribut de type char. */</span>
   <span class="keyword">private</span> <span class="keyword">char</span> mc;
   
   <span class="comment2">/** Attribut de type enum. */</span>
   <span class="keyword">private</span> <span class="keyword">enum</span> Sexe
   {
      <span class="comment2">/** Masculin. */</span>
      MASCULIN, 
      <span class="comment2">/** Féminin. */</span>
      FEMININ
   }
   
   <span class="comment2">/** Attrbut sexe. */</span>
   <span class="keyword">private</span> <span class="keyword">volatile</span> Sexe mx;
   
   <span class="comment2">/** Attribut de type liste. */</span>
   <span class="keyword">private</span> List&lt;String&gt; myList;
   
   <span class="comment2">/** Variable de test. */</span>
   <span class="keyword">private</span> Object var123ForTest;
   
   <span class="comment2">/** Constante. */</span>
   <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">int</span> NB = <span class="number">10</span>;
   
   <span class="comment2">/**
    * &lt;p&gt;Constructeur.&lt;/p&gt;
    */</span>
   <span class="keyword">public</span> Source1()
   {
      <span class="keyword">super</span>();
      init();
      method1();
      method2();
      method3();
      method4();
      method5();
   }
   
   <span class="comment2">/**
    * &lt;p&gt;Initialisation des variables.&lt;/p&gt;
    */</span>
   <span class="keyword">protected</span> <span class="keyword">void</span> init()
   {
      <span class="keyword">this</span>.mb = <span class="keyword">true</span>;
      <span class="keyword">this</span>.mi = <span class="number">0</span>;
      <span class="keyword">this</span>.ml = <span class="number">0L</span>;
      <span class="keyword">this</span>.mf = <span class="number">0.0F</span>;
      <span class="keyword">this</span>.md = <span class="number">0.0E+0</span>;
      <span class="keyword">this</span>.mf = <span class="number">0.0f</span>;
      <span class="keyword">this</span>.md = <span class="number">0.0e+0</span>;
      <span class="keyword">this</span>.my = <span class="number">0</span>;
      <span class="keyword">this</span>.ms = <span class="number">0</span>;
      <span class="keyword">this</span>.mc = <span class="char">'\0'</span>;
      <span class="keyword">this</span>.mx = Sexe.FEMININ;
      <span class="keyword">this</span>.myList = <span class="keyword">new</span> ArrayList&lt;String&gt;();
   }
   
   <span class="comment2">/**
    * &lt;p&gt;Méthode pour les booléens et le test if/else.&lt;/p&gt;
    */</span>
   <span class="keyword">private</span> <span class="keyword">void</span> method1()
   {
      <span class="keyword">assert</span> (<span class="keyword">this</span>.mi == <span class="number">0</span>);
      
      <span class="keyword">if</span>(<span class="keyword">this</span>.mx == Sexe.MASCULIN)
      {
         <span class="keyword">this</span>.mb = <span class="keyword">true</span>;
      }
      <span class="keyword">else</span>
      {
         <span class="keyword">this</span>.mb = <span class="keyword">false</span>;
      }
   }
   
   <span class="comment2">/**
    * &lt;p&gt;Méthode pour le switch.&lt;/p&gt;
    */</span>
   <span class="keyword">private</span> <span class="keyword">void</span> method2()
   {
      <span class="keyword">switch</span>(<span class="keyword">this</span>.mc)
      {
      <span class="keyword">case</span> <span class="char">'\0'</span>:
         <span class="keyword">break</span>;
      <span class="keyword">case</span> <span class="char">'\''</span>:
         <span class="keyword">break</span>;
      <span class="keyword">case</span> <span class="char">'&lt;'</span>:
         <span class="keyword">break</span>;
      <span class="keyword">default</span>:
         <span class="keyword">this</span>.ml = <span class="keyword">this</span>.ml * <span class="number">3</span> / <span class="number">2</span> + <span class="number">1</span>;
         <span class="keyword">break</span>;
      }
   }
   
   <span class="comment2">/**
    * &lt;p&gt;Méthode pour le while.&lt;/p&gt;
    */</span>
   <span class="keyword">private</span> <span class="keyword">void</span> method3()
   {
      <span class="keyword">this</span>.mi = <span class="number">1</span>;
      <span class="keyword">do</span>
      {
         <span class="keyword">if</span>(<span class="keyword">this</span>.mi &gt; <span class="number">10</span> &amp;&amp; (<span class="keyword">this</span>.mi &lt; <span class="number">0</span> || <span class="keyword">this</span>.mi == <span class="number">1024</span>))
         {
            <span class="keyword">break</span>;
         }
         <span class="keyword">this</span>.mi += <span class="keyword">this</span>.mi;
      }
      <span class="keyword">while</span>(<span class="keyword">this</span>.mi &lt; NB);
   }
   
   <span class="comment2">/**
    * &lt;p&gt;Méthode pour le for.&lt;/p&gt;
    */</span>
   <span class="keyword">private</span> <span class="keyword">synchronized</span> <span class="keyword">void</span> method4()
   {
      <span class="keyword">for</span>(<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; NB; j++)
      {
         <span class="keyword">if</span>(j % <span class="number">2</span> == <span class="number">0</span>)
         {
            <span class="keyword">this</span>.myList.add(String.valueOf(j));
         }
         <span class="keyword">else</span>
         {
            <span class="keyword">continue</span>;
         }
      }
   }
   
   <span class="comment2">/**
    * &lt;p&gt;Méthode pour les exceptions.&lt;/p&gt;
    * <b>@throws</b> NumberFormatException Si une division par zéro se produit.
    */</span>
   <span class="keyword">private</span> <span class="keyword">void</span> method5() <span class="keyword">throws</span> NumberFormatException
   {
      <span class="keyword">try</span>
      {
         <span class="keyword">this</span>.md = <span class="keyword">this</span>.mi / <span class="keyword">this</span>.mf;
      }
      <span class="keyword">catch</span>(NumberFormatException e)
      {
         <span class="keyword">throw</span> <span class="keyword">new</span> NumberFormatException(<span class="string">"Division par zéro."</span>);
      }
      <span class="keyword">finally</span>
      {
         <span class="keyword">if</span>(<span class="keyword">this</span>.var123ForTest <span class="keyword">instanceof</span> List)
         {
            <span class="keyword">this</span>.var123ForTest = <span class="keyword">null</span>;
         }
      }
   }
   
   <span class="comment2">/**
    * &lt;p&gt;Méthode native.&lt;/p&gt;
    * <b>@param</b> msg Le message à afficher.
    */</span>
   <span class="keyword">private</span> <span class="keyword">native</span> <span class="keyword">void</span> showMessage(String msg);
   
   <span class="comment2">/**
    * &lt;p&gt;Redéfinition de la méthode toString().&lt;/p&gt;
    * <b>@return</b> Une représentation de l'objet.
    */</span>
   <span class="annotation">@Override</span>
   <span class="keyword">public</span> String toString()
   {
      <span class="keyword">return</span> <span class="string">"Ceci est une implémentation de la méthode \"toString()\""</span>;
   }
   
   <span class="comment2">/**
    * Interface pour les mots clés relatif aux interfaces.
    */</span>
   <span class="annotation">@SuppressWarnings</span>(value = <span class="string">"unused"</span>)
   <span class="keyword">private</span> <span class="keyword">interface</span> MyInterface
   {
      <span class="comment2">/** Méthode abstraite. */</span>
      <span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">void</span> methodeAbstraite();
   }
   
   <span class="comment2">/**
    * &lt;p&gt;Débute l'exécution de l'application.&lt;/p&gt;
    * <b>@param</b> args Les paramètres de la ligne de commande.
    */</span>
   <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> main(String[] args)
   {
      <span class="keyword">new</span> Source1();
   }
}
</pre>